<?php include ('./_config.inc.php');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'; ?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>RSS Feed: <?php echo $lico['title']; ?></title>
    <link><?php echo $lico['baseurl.ssl']; ?></link>
    <description><?php echo $lico['description']; ?></description>
    <language><?php echo join(",", $lico['allowed_lang']); ?></language>
    <pubDate><?php echo gmdate("r"); ?></pubDate>
    <lastBuildDate><?php echo gmdate("r"); ?></lastBuildDate>
    <image>
      <title><?php echo $lico['title']; ?></title>
      <link><?php echo $lico['baseurl.ssl']; ?></link>
      <url><?php echo $lico['baseurl.ssl']; ?>/gfx/logo.png</url>
    </image>
    <?php
    
    $items = array();
    $sel = "SELECT * FROM news ORDER BY stamp DESC LIMIT 0,10;";
    $ret = $db->getAll_assoc($sel);
    for ($a=0; $a<count($ret); $a++) {
      $id = intval($ret[$a]['id']);
      $subject = trim($ret[$a]['subject']);
      $text = trim($ret[$a]['body']);
      $stamp = intval($ret[$a]['stamp']);
      $items['stamp'][] = $stamp;
      $items['subject'][] = "[News] ".$subject;
      $items['text'][] = $text;
      $items['id'][] = $id;
      $items['type'][] = "news";
    }
    $sel = "SELECT * FROM changelog ORDER BY stamp DESC LIMIT 0,10;";
    $ret = $db->getAll_assoc($sel);
    for ($a=0; $a<count($ret); $a++) {
      $id = intval($ret[$a]['id']);
      $subject = trim($ret[$a]['version']);
      $text = trim($ret[$a]['logentry']);
      $stamp = intval($ret[$a]['stamp']);
      $items['stamp'][] = $stamp;
      $items['subject'][] = "[ChangeLog] ".$subject;
      $items['text'][] = $text;
      $items['id'][] = $id;
      $items['type'][] = "change";
    }
    array_multisort($items['stamp'], SORT_DESC, SORT_NUMERIC, 
                    $items['id'], $items['subject'], $items['text'], $items['type']);
    
    for($a=0; $a<count($items['stamp']); $a++) {
      echo "    <item>\n";
      echo "      <title>".$items['subject'][$a]."</title>\n";
      echo "      <link>".$lico['baseurl.ssl']."/".($items['type'][$a]=="news"?"news":"changelog").".html#".$items['id'][$a]."</link>\n";
      echo "      <description>".substr(strip_tags($items['text'][$a]), 0, 300)."...</description>\n";
      echo "      <pubDate>".gmdate("r", $items['stamp'][$a])."</pubDate>\n";
      echo "      <guid>".$lico['baseurl.ssl']."/".($items['type'][$a]=="news"?"news":"changelog").".html#".$items['id'][$a]."</guid>\n";
      echo "      <content:encoded><![CDATA[".$items['text'][$a]."]]></content:encoded>\n";
      echo "    </item>\n";
    }
    ?>
  </channel>
</rss>